/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PANDA_TOOLING_TEST_JS_METHOD_EVENT_TEST_H
#define PANDA_TOOLING_TEST_JS_METHOD_EVENT_TEST_H

#include "test_util.h"

namespace ark::tooling::test {
class JsMethodEventTest : public ApiTest {
public:
    JsMethodEventTest()
    {
        vmDeath = [this]() {
            ASSERT_EQ(methodEntryExitCount_, 0);
            ASSERT_NE(methodEntryCount_, 0);
            return true;
        };

        methodEntry = [this](PtThread, Method *) {
            methodEntryExitCount_++;
            methodEntryCount_++;
            return true;
        };

        methodExit = [this](PtThread, Method *, bool, VRegValue) {
            methodEntryExitCount_--;
            return true;
        };
    }

    std::pair<const char *, const char *> GetEntryPoint() override
    {
        return {pandaFile_.c_str(), entryPoint_.c_str()};
    }

private:
    std::string pandaFile_ = "js/Sample.abc";
    std::string entryPoint_ = "_GLOBAL::func_main_0";

    int methodEntryExitCount_ = 0;
    int methodEntryCount_ = 0;
};

inline std::unique_ptr<ApiTest> GetJsMethodEventTest()
{
    return std::make_unique<JsMethodEventTest>();
}
}  // namespace ark::tooling::test

#endif  // PANDA_TOOLING_TEST_JS_METHOD_EVENT_TEST_H
